<?php
/**
 * Created by PhpStorm.
 * User: 10037
 * Date: 2022/5/27
 * Time: 22:32
 */

namespace app\admin\model;


use think\Model;

class User extends Model
{
    protected $pk='id';

    public function selectIsUser($username,$password){
       $result= $this->where([['username','=',$username],['status','=',1]])->find();
       if(empty($result)){
           return [
               'flag'=>false
           ];
       }

       if($result['password']!==$password){
           return [
               'flag'=>false
           ];
       }

       return [
           'flag'=>true,
           'id'=>$result['id'],
           'img'=>$result['userImg']
       ];
    }

    public function addNewUser($data){
        return $this->save($data);
    }

    public function selectUserAll($page){
        return $this->where('status','=',0)->where('delete','=',0)->page($page,10)->select();
    }

    public function selectUserCount(){
        return $this->where('status','=',0)->where('delete','=',0)->count();
    }

    public function selectIdUser($id){
        return $this->find($id);
    }

    public function deleteUser($id){
        $result= $this->find($id);
        $result['delete']=1;
        return $result->save();
    }

    public function likeSelect($text){
        return $this->where('username','like','%'.$text.'%')->select();
    }

    public function selectTimeUserCount($date){
        return $this->where('addUserTime','=',$date)->count();
    }
}